package com.wxzl.community.common.widget;

import android.view.View;
import android.widget.Button;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.contrarywind.view.WheelView;
import com.wxzl.community.common.R;

import java.util.List;


public class OptionBottomFragment extends BottomSheetFragBase {
    @Override
    public int getLayoutResId() {
        return R.layout.bottom_picker;
    }

    private final List<String> mData;
    public OptionBottomFragment(List<String> mData) {
        this.mData = mData;
    }

    /**
     * 初始化View和设置数据等操作的方法
     */
    @Override
    public void initView() {
        WheelView wheelview = rootView.findViewById(R.id.wheelview);
        wheelview.setCyclic(false);
        wheelview.setAdapter(new ArrayWheelAdapter(mData));
        Button   btnOk     = rootView.findViewById(R.id.btnOk);
        Button btnCancel = rootView.findViewById(R.id.btnCancel);
        btnOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (selectedListener !=null)
                {
                    selectedListener.onSelected(mData.get(wheelview.getCurrentItem()),wheelview.getCurrentItem());

                }
                dismiss();
            }
        });
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });


    }

    public void setSelectedListener(OnSelectedListener selectedListener) {
        this.selectedListener = selectedListener;
    }

   private OnSelectedListener selectedListener;

    public interface OnSelectedListener{
           void  onSelected(String text, int index) ;

    }
}
